package com.base.system.managedBean.baseBean;

import java.io.Serializable;

import javax.faces.model.SelectItem;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.SelectItems;

import com.base.common.provider.SelectItemsProvider;
import com.base.commons.SpringBeanHolder;
import com.base.organization.entity.Position;
import com.base.organization.service.IPositionDAO;
import com.base.security.SecurityReplace;

public abstract class BasePositionBean implements Serializable {
	protected IPositionDAO postDao = SpringBeanHolder.getBean("positionDAO");
	protected Position post;
	// 直接上级
	@Bind(id = "directChief", attribute = "value")
	protected String directChief;
	@Bind(id = "directChief_name", attribute = "value")
	protected String directChief_name;
	// 直接下级
	@Bind(id = "directJunior", attribute = "value")
	protected String directJunior;
	@Bind(id = "directJunior_name", attribute = "value")
	protected String directJunior_name;

	@Bind(id = "name", attribute = "value")
	protected String name;

	@Bind(id = "postGrade", attribute = "value")
	protected String postGrade;

	@Bind(id = "postNumber", attribute = "value")
	protected String postNumber;

	@Bind(id = "postEssential", attribute = "value")
	protected String postEssential;
	// 岗位类别
	@Accessible
	protected SelectItem[] postType_items;
	@Bind(id = "postType")
	@SelectItems(source = "#{this.postType_items}")
	protected String postType;

	@Accessible
	protected SelectItem[] enable_items = SelectItemsProvider.getYesNo();
	@Bind(id = "enable")
	@SelectItems(source = "#{this.enable_items}")
	protected String enable = Boolean.TRUE.toString();

	protected void setPostProperty() {
		post.setName(name);
		post.setPostGrade(postGrade);
		if (postNumber != null && !"".equals(postNumber))
			post.setPostNumber(Long.parseLong(postNumber));
		post.setDirectChief(directChief);
		post.setDirectJunior(directJunior);
		post.setPostEssential(postEssential);
		// post.setPostType(postType);
		post.setEnable(new Boolean(enable).booleanValue());
	}

	protected void getPositonProperty() {
		name = post.getName();
		postGrade = post.getPostGrade();
		if (post.getPostNumber() != null)
			postNumber = post.getPostNumber().toString();
		directChief = post.getDirectChief();
		directChief_name = SecurityReplace.replaceUserFullName(post
				.getDirectChief());
		directJunior = post.getDirectJunior();
		directJunior_name = SecurityReplace.replaceUserFullName(post
				.getDirectJunior());
		postEssential = post.getPostEssential();
		postType = post.getPostType();
		enable = String.valueOf(post.isEnable());
	}

}
